package com.lagou.edu.controller;

import com.lagou.edu.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by Ju·Felix on 2020/5/5.
 */
@Controller
@RequestMapping("/user")
public class LoginController {

    /**
     * 向用户登录页面跳转
     */
    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String toLogin() {
        return "login";
    }

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public String login(User user, Model model, HttpSession session) throws Exception {
        String username=user.getUsername();
        String password=user.getPassword();

        if ("admin".equals(username) && "admin".equals(password)) {
            //将用户对象添加到Session中
            session.setAttribute("username", "admin");
            //重定向到infos页面的跳转方法
            return "redirect:/resume/infos";
        }
        model.addAttribute("msg", "登录验证失败，请登录！");
        return "login";
    }

}
